//导入request.js 工具
import request from "@/utils/request";

export const userRegisterService = (registerData) => {
  const params = new URLSearchParams();
  for (let key in registerData) {
    params.append(key, registerData[key]);
  }
  return request.post("/user/register", params);
};

export const userLoginService = (loginData) => {
  const params = new URLSearchParams();
  for (let key in loginData) {
    params.append(key, loginData[key]);
  }
  return request.post("/user/login", params);
};

//用户条件分页列表查询
export const userPageListService = (params) => {
  return request.get("/user/findPageAll",{params:params});
};

//修改用户信息的请求
export const userUpdateService = (userData) => {
  return request.post("/user/update", userData);
};
//删除用户信息请求
export const userDeleteService = (userId) => {
  return request.delete("/user/delete" ,  { params: { userId } });
};
//获取当前用户基本信息
export const userInfoService = () => {
  return request.get("/user/info");
};
//获取不同用户基本信息
// src/api/user.js
export const userInfoByNameService = (username) => {
  return request.get("/user/infoByName", { params: { username } });
};
//发送更新密码请求
export const userUpdatePasswordService = (userData) => {
  return request.post("/user/updatePassword", userData);
};
//头像修改
export const userUpdateAvatarService = (avatarUrl) => {
  const params =new URLSearchParams();
  params.append("avatarUrl",avatarUrl);
  return request.patch("/user/updateAvatar", params);
};
//批量删除用户请求
export const userBatchDeleteService = (multipleSelection) => {
  return request.put('/user/batchDelete', multipleSelection );
};
export const expUserServer =()=>{
  return request({
    url: "/user/export",
    method: 'get',
    responseType: 'blob' // 设置响应类型为blob
  });
}
export const UserUploadService= (file) => {
  const formData = new FormData();
  formData.append('file', file);
  return request({
    url: "/user/upload",
    method: 'post',
    data: formData, // 使用 data 而不是 formData
    headers: {
      'Content-Type': undefined // 让 axios 自动设置 Content-Type
    }
  });
};

